<?php
/**
 *author:栗超
 *address:2788547340@qq.com
 * 2016/9/4 23:58
 */ 
namespace Home\Controller;
use Common\Model\Address;
use Hdphp\Controller\Controller;

class UserController extends Controller{
    public function index(){
    //账户信息密码修改
    if(IS_POST){
        //新密码不的少于6位
        $newPassword=Q('post.new_password');
        if(strlen($newPassword)<6){
            View::error('新密码不得少于6位');
        }
        //两次密码是否一致
        $r_password=Q('post.r_password');
        if($newPassword!=$r_password){
            View::error('两次密码不一致');
        }
        //旧密码是否正确
        $uid=$_SESSION['uid'];
        $oldPassword=Q('post.old_password','','md5');
        if($oldPassword!=$_SESSION['upassword']){
            View::error('原密码不正确');
        }
        //修改密码
        Db::table('user')->where("uid={$uid}")->update(['upassword'=>md5($newPassword)]);
        View::success('修改密码成功，请您重新登陆','Login/index');
    }
    View::make();
}
public function add(){
    $addressModel=new Address();
    $addressData=$addressModel->where("user_uid",$_SESSION['uid'])->get();
    if(IS_AJAX){
        $add=$addressData->store();
        echo json_encode($add);
        }
        View::with('addressData',$addressData);
        View::make();
    }
    public function del(){
        $aid=Q('get.aid',0,'intval');
//        p($aid);
//        $this->model->where("aid={$aid}")->delete();
        $addressModel=new Address();
        $addressModel->where("aid={$aid}")->delete();
        View::success('删除成功','User/add');
    }
    public function form(){
        View::make();
    }
}